
var startDate = '';
var endDate = '';
var List = [];
var user = [];
var userid = 0;

//分页查询
var limit = 5;// 每页多少条
var currPage = 1;// 当前页
var allPage = 1;// 总页数
var start = 1;// 开始查询条数
var end = 5;// 结束查询条数
var count = 0;// 默认共多少条数据

// getLog();
function getLog(){
    $.ajax({
		url : ajax_host +'userlog.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
				List = resp.list;
				console.log("列表："+resp.list);
				renderTable(resp.list);
			}else{
				layer.alert('获取日志失败')
			}
		}
	})
}
function renderTable(arr){
	var str = `<tr>
		<th>用户名称</th>
		<th>操作事项</th>
		<th>操作时间</th>
		<th>操作</th>	
	</tr>`;
	for(var i = 0;i<arr.length;i++){
		var a = arr[i];
		str += 
		   `<tr>
            <td>${a.userName}</td>
            <td>${a.actionName}</td>
            <td>${a.actionDate}</td>
			<th>
			<a href = "###" onclick="del(${i})">删除</a>
			</th>
		</tr>`;
		
	}
	html('table',str);
}


 getuser();
function getuser(){
	$.ajax({
		url : ajax_host +'getuserName.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
				user = resp.list;
				console.log("列表："+user);
				 renderType(user)
			}
		}
	})
}
function renderType(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].uId}">${arr[i].uName}</option>`;
	}
	html('user',str);
}
function change(){
    userid = val('user');
    console.log('管理员id：'+userid);
}

function getstartDate(){
    startDate = document.getElementById('start').value;
    console.log(startDate);
	
}
function getendDate(){
	endDate = document.getElementById('end').value;
	console.log(endDate);
}
selectLog();
function selectLog(){
	console.log(userid);
	console.log(startDate);
	console.log(endDate);
	
	$.ajax({
		url:ajax_host+'selectuserlog.act',
        dataType:'JSON',
        data:{
            uid : userid,
            start : startDate,
			end : endDate,
			startpage : start,
			limitpage : limit    
		},
    	success:function(resp){
            
    		if(resp.success){
                List = resp.list;
				console.log("列表："+List);
                // getlist()
				renderTable(resp.list);
				// 总页数=记录数/每页记录
				count = resp.count;
				console.log('总记录数:'+count)
				allPage=count%limit==0?(count/limit):(parseInt(count/limit+1));
				console.log('总页数:'+allPage);
				$("#pager").html(currPage+"/"+allPage);
    		}else{
                layer.alert('获取文件类型失败')
            }
    	},
    	
    });
}

function pagenext() {
	if (currPage + 1 > allPage) {
		alert("当前已经是最后一页");
		return;
	}
	start = start + limit;
	currPage = currPage + 1;
	selectLog();
};

function pageback() {
	if (currPage - 1 == 0) {
		alert("当前已经是第一页");
		return;
	}
	start = start - limit;
	currPage = currPage - 1;
	selectLog();
};
